Καλώς ορίσατε στο dotNETZone.gr - Σύνδεση | Εγγραφή | Βοήθεια
σε

 

Αρχική σελίδα Ιστολόγια Συζητήσεις Εκθέσεις Φωτογραφιών Αρχειοθήκες

Πρόβλημα με C#

Îåêßíçóå áðü ôï ìÝëïò equilibriumg. Τελευταία δημοσίευση από το μέλος equilibriumg στις 14-05-2011, 01:46. Υπάρχουν 2 απαντήσεις.
Ταξινόμηση Δημοσιεύσεων: Προηγούμενο Επόμενο
  •  13-05-2011, 23:44 65754

    Πρόβλημα με C#

    Καλησπέρα. Έχω φτιάξει μια φόρμα aspx C# σε visual studio 2010.

    <div>
        
            </asp:TextBox ID="onoma" runat="server">onoma<br />
    &nbsp;</asp:TextBox ID="eponimo" runat="server">eponimo<br />
    &nbsp;</asp:TextBox ID="ar_taftotitas" runat="server">ar_taftotitas<br />
    &nbsp;</asp:TextBox ID="tilefono1" runat="server">tilefono1
        
            <br />
            <br ID="Button1" runat="server" Text="Sen Information" OnClick="EnterData" />
    &nbsp;</asp:Label ID="Label1" runat="server" Text="Status">
        
        </div>

    Στο cs αρχείο βάζω τον παρακάτω κώδικα για να κάνω εγγραφή στη βάση. Δυστυχώς ενώ όλα φαίνονται να λειτουργούν σωστά(παίρνω το μήνυμα “Data has been sent”) εγγραφή στη βάση δεν γίνετε.  

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    
    namespace i_vasi_mou
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            
            private string strInsert;
            private SqlCommand sqlCmd;
            private SqlConnection hookUp;
    
            protected void EnterData(object sender, EventArgs e)
            {
                hookUp = new SqlConnection("Server=localhost\\SqlExpress; Database=i_vasi_mou;" +
    "Integrated Security=True");
                strInsert = "INSERT INTO pelates(onoma,eponimo,ar_taftotitas,tilefono1,";
                strInsert += "(@onoma,@eponimo,@ar_taftotitas,@tilefono1)";
                sqlCmd = new SqlCommand(strInsert, hookUp);
                sqlCmd.Parameters.Add("@onoma", onoma.Text);
                sqlCmd.Parameters.Add("@eponimo", eponimo.Text);
                sqlCmd.Parameters.Add("@ar_taftotitas", ar_taftotitas.Text);
                sqlCmd.Parameters.Add("@tilefono1", tilefono1.Text);
                hookUp.Open();
                sqlCmd.ExecuteNonQuery();
                hookUp.Close();
                Label1.Text = "Data has been sent";
            }
        }
    }


  •  14-05-2011, 00:57 65756 σε απάντηση της 65754

    Απ: Πρόβλημα με C#

    Δοκίμασε αν θές τον παρακάτω κώδικα :

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
            private void button1_Click(object sender, EventArgs e)
            {
                int iaffected = 0 ;
    
                hookUp = new SqlConnection("Server=localhost\\SqlExpress; Database=i_vasi_mou; Integrated Security=True") ;
             
                strInsert = "INSERT INTO pelates ( onoma, eponimo, ar_taftotitas, tilefono1 ) " ;
                strInsert += "VALUES ( @onoma, @eponimo, @ar_taftotitas, @tilefono1 )" ;
                
                sqlCmd = new SqlCommand(strInsert, hookUp) ;
    
                sqlCmd.Parameters.Add("@onoma", SqlDbType.NVarChar) ;
                sqlCmd.Parameters["@onoma"].Value = "Onoma" ;
    
                sqlCmd.Parameters.Add("@eponimo", SqlDbType.NVarChar) ;
                sqlCmd.Parameters["@eponimo"].Value = "Eponimo" ;
    
                sqlCmd.Parameters.Add("@ar_taftotitas", SqlDbType.NVarChar) ;
                sqlCmd.Parameters["@ar_taftotitas"].Value = "H 7876545" ;
    
                sqlCmd.Parameters.Add("@tilefono1", SqlDbType.NVarChar) ;
                sqlCmd.Parameters["@tilefono1"].Value = "1234" ;
    
                hookUp.Open() ;
                iaffected = sqlCmd.ExecuteNonQuery() ;
                hookUp.Close() ;
    
                if (iaffected > 0 ) 
                    MessageBox.Show("Data has been sent") ;
            }

  •  14-05-2011, 01:46 65758 σε απάντηση της 65756

    Απ: Πρόβλημα με C#

    Πολλά - Πολλά Ευχαριστώ! Δούλεψε
Προβολή Τροφοδοσίας RSS με μορφή XML
Με χρήση του Community Server (Commercial Edition), από την Telligent Systems